perm filename A53.TEX[106,PHY] blob sn#807761 filedate 1985-11-15 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	\magnification\magstephalf
C00006 ENDMK
C⊗;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a53.tex[106,phy] \today\hfill}

\bigskip
\line{\bf Rule of good programming practice.\hfill}


Good programmers do some of their calculations by hand.  A computer program is
like a submarine; you know it's there, but you can't see what it's doing.
Until it's too late.

Human beings, unlike computers, have the gift of recognizing patterns in events.
They are also blessed by laziness.  To evaluate the polynomial 
$a+bx+cx↑2+dx↑3+ex↑4$
in the obvious way requires seven multiplications and four additions. If you have
to do it by hand a few dozen times, you get strongly motivated to notice a common
factor, and calculate 
$a+x(b+cx+dx↑2+ex↑3)$ using one fewer multiplication.  
Then you see a common factor of~$x$ in $cx+dx↑2+ex↑3$.
From
there, it is not far to Horner's Rule: 
$a+x\bigl(b+x\bigl(c+x\bigl(d+x(e)\bigr)\bigr)\bigr)$, saving three
multiplications.

The next best thing to executing an algorithm by hand is to get as much information
as you can about how a computer executes it.  You can,
for example,  use an array of counters to
find out how often each iteration body and procedure body in your program is
executed.  (Some Pascal implementations provide this service automatically;
it is a very useful tool, both for diagnosing errors and for tuning
program performance.)
An old programmer's rule of thumb declares that 80\%\ of the time is
spent in 20\%\ of the program, and 80\%\ of {\sl that\/} 
time is spent in 20\%\ of the 20\%.
Find that hyperactive 4\%\ and make it faster; you may make the entire program
more than twice as fast.




\bigskip
\parindent0pt
\copyright 1984 Robert W. Floyd

First draft April 4, 1984

\bye